<%--
  Created by IntelliJ IDEA.
  User: LT
  Date: 2018-10-25
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <script>


        $(function () {
            $("#usertb").bootstrapTable({
                url:'${pageContext.request.contextPath}/role/queryRolePage',
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                //设置每页多少条数据
                pageSize:2,
                pageList:[2,4,8,16],
                height:300,
                pageNumber:1,
                //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含
                //limit, offset, search, sort, order 否则, 需要包含:
                //pageSize, pageNumber, searchText, sortName, sortOrder.
               // 返回false将会终止请求。
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        name:$("#username").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        field:'id',
                        title:'编号'
                    },
                    {
                        field:'rname',
                        title:'名字'
                    },
                    {
                        title:'操作',
                        formatter:function(value,row,index){
                            return "<a href='javascript:tofenpei()'>分配权限</a>" ;
                        }
                    }

                ]
            }) ;
        }) ;

        function searcha() {
            var opts = $("#usertb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var name = $("#name").val() ;
            $.post("${pageContext.request.contextPath}/role/queryRolePage",{'name':name,'limit':limit,'offset':offset},function (data) {
               // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#usertb").bootstrapTable('load',data) ;
            })
        }

        function tofenpei() {
            alert("分配权限") ;
        }
    </script>

</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">角色列表</h3>
    </div>
    <div class="panel-body">
        <div class="row" style="margin-bottom: 10px">
            <form action="" class="form-inline">
                <div class="col-sm-4">
                   <button class="btn btn-primary">
                       <span class="glyphicon glyphicon-plus"></span>增加
                   </button>
                </div>
            <div class="col-sm-4 col-sm-offset-4 text-right">

                    <input id="name" type="text" class="form-control">
                    <input onclick="searcha()" type="button" class="btn btn-primary" value="查询">


            </div>
            </form>
        </div>
        <table id="usertb"></table>
    </div>
</div>


</body>
</html>
